package com.aaa.controller.mht;

import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.mht.TMhtSub;
import com.aaa.service.mht.TMhtSubService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * (mhtaSub)表控制层
 *
 * @author 刘鸿飞
 * @since 2022-10-22 17:05:00
 */
@Controller
@RequestMapping("tMhtSub")
public class TMhtSubController {
    /**
     * 服务对象
     */
    @Autowired
    private TMhtSubService tMhtSubService;

    // 批量导入数据
    @Resource
    private TMhtSubService fileService;
    @PostMapping(value = "/import")
    @ResponseBody
    public LayData storageService(MultipartFile file) {

       fileService.dealFile(file);
       return new LayData(true);
    }

    @GetMapping
    @ResponseBody
    public LayData getAllSub(MyPage myPage, TMhtSub tMhtSub){
        PageInfo allSub = tMhtSubService.findAllSub(myPage, tMhtSub);
        return new LayData(allSub);
    }

    /**
     * mht做题页面
     * @param myPage
     * @param request
     * @return
     */
    @GetMapping("index")
    public String getIndexAllSub(MyPage myPage, HttpServletRequest request){
        myPage.setLimit(100);
        myPage.setPage(1);
        PageInfo all = fileService.getAll(myPage);
        request.setAttribute("allsub",all);

        return "/mht/index";

    }
    @PostMapping("edit")
    @ResponseBody
    public LayData edit(TMhtSub tMhtSub){
//        添加和编辑共用
        boolean b = tMhtSubService.updEdit(tMhtSub);
        return new LayData(b);
    }
    @PostMapping("del")
    @ResponseBody
    public LayData del(Integer id,Integer[] mhtno){
//        删除试题
        boolean del = tMhtSubService.del(id,mhtno);
        return new LayData(del);
    }
    /*
    * 批量删除
    * */
    @RequestMapping("delbath")
    @ResponseBody
    public LayData delbath(@RequestParam Integer[] id, @RequestParam Integer[] mhtno){
        boolean delsdsbath = tMhtSubService.delsdsbath(id,mhtno);
        System.out.println("delsdsbath = " + delsdsbath);
        return new LayData(delsdsbath);
    }

}

